package com.example.demo.pattern.chainofresponsibility;

/** 责任链模式
 * @description
 * @author Jin Tong
 * @date 2019-02-26 14:39
 */
public abstract class AbstractLogger {
    static final int DEBUG = 1;
    static final int INFO = 2;
    static final int WARN = 3;

    protected int level;

    //责任链中的下一个元素
    private AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger nextLogger) {
        this.nextLogger = nextLogger;
    }

    public void logMessage(int level,String message){
        if(this.level <= level){
            this.write(message);
        }
        if(nextLogger != null){
            nextLogger.logMessage(level,message);
        }
    }

    abstract void write(String message);
}
